#include <QHBoxLayout>
#include <QLineEdit>
#include <QApplication>
#include <QDesktopWidget>
#include <QPropertyAnimation>
#include <QGraphicsPixmapItem>
#include <QGraphicsColorizeEffect>
#include <QGraphicsOpacityEffect>
#include <QGraphicsScene>
#include "testing-panel.h"

using namespace Core;

TestingPanel::TestingPanel(QObject *parent) : QObject(parent)
{
    _screen = NULL;
}

void TestingPanel::show()
{    
    _screen = new QWidget();
    _screen->setWindowState(Qt::WindowFullScreen);
    _screen->setStyleSheet("background-color: black");

    QGraphicsView* view = new QGraphicsView(_screen);
    view->setStyleSheet("border: 0px");
    view->setGeometry(QApplication::desktop()->screen()->rect());

    QGraphicsScene* scene = new QGraphicsScene(_screen);
    view->setScene(scene);

    view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);

    QPixmap p = QPixmap::grabWindow(QApplication::desktop()->screen()->winId());
    QGraphicsPixmapItem *i = scene->addPixmap(p);
    AnimatedPixmap* ap = new AnimatedPixmap(i);

    QHBoxLayout* l = new QHBoxLayout(_screen);

    _container = new QWidget(_screen);
    _container->setFixedSize(400, 200);
    _container->setStyleSheet("background-color: red");

    l->addWidget(_container);

    _screen->show();

    QPropertyAnimation *animation = new QPropertyAnimation(ap, "opacity", _screen);
    animation->setDuration(1000);
    animation->setStartValue(1);
    animation->setEndValue(0.3);

    animation->start();
}

void TestingPanel::hide()
{
    if (_screen != NULL)
        _screen->deleteLater();

    _screen = NULL;
}

QWidget* TestingPanel::widget()
{
    return _container;
}
